# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.volume_spark_sql_operator import VolumeRichSqlSensor
from spmi_volume.dim.dim_spmi_pcp_capacity_cost_mt import spmi_dim__dim_spmi_pcp_capacity_cost_mt
from spmi_volume.dim.dim_spmi_pcp_waybill_mt import spmi_dim__dim_spmi_pcp_waybill_mt
from spmi_volume.dim.dim_spmi_pcp_center_cost_mt import spmi_dim__dim_spmi_pcp_center_cost_mt
from spmi_volume.ods.spmi_pcp_piece_bill_face_sum import spmi_ods__spmi_pcp_piece_bill_face_sum
from spmi_volume.ods.spmn_pcp_config_relation import spmi_ods__spmn_pcp_config_relation


#Hive表名
hive_table = "dwd_1_five_cost"
#任务名
task_id = f"dwd_1_five_cost{hive_table}"

dwd_1_five_cost = VolumeRichSqlSensor(
    task_id=f'{task_id}',
    task_concurrency=1,
    pool_slots=2,
    master='yarn',
    name=f'{task_id}_{{{{ execution_date | date_add(1) | cst_ds }}}}',
    sql=f'spmi_volume/dwd/{hive_table}/execute.sql',
    retries=0,
    pool='spmi_piece',
    email=['yushuo@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    execution_timeout=timedelta(hours=6),
    yarn_queue='route',

    driver_memory='4G',
    driver_cores=2,
    executor_cores=6,
    executor_memory='24G',
    num_executors=80,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 120,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 600,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '4G',  # 堆外内存
          'spark.sql.shuffle.partitions': 6400,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 1000,
              'hive.exec.max.dynamic.partitions.pernode': 1000,
              },
)
dwd_1_five_cost << [spmi_dim__dim_spmi_pcp_capacity_cost_mt,spmi_dim__dim_spmi_pcp_waybill_mt,spmi_dim__dim_spmi_pcp_center_cost_mt,spmi_ods__spmi_pcp_piece_bill_face_sum,spmi_ods__spmn_pcp_config_relation]